<%--
  Created by IntelliJ IDEA.
  User: 31036
  Date: 2025/4/8
  Time: 14:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="../../static/layui/css/layui.css" rel="stylesheet">
    <script src="../../static/js/jquery-1.8.3.js"></script>
</head>
<body>
<form class="layui-form layui-row layui-col-space16">
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-username"></i>
            </div>
            <input type="text" name="customerName" value="" placeholder="用户名称" class="layui-input"
                   lay-affix="clear">
        </div>
    </div>
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-date">时间查询</i>
            </div>
            <input type="date" name="startTime" id="startTime" placeholder="初始时间"
                   class="layui-input demo-table-search-date">
        </div>
    </div>
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-date">-</i>
            </div>
            <input type="date" name="endTime" id="endTime" placeholder="末尾时间"
                   class="layui-input demo-table-search-date">
        </div>
    </div>

    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-username"></i>
            </div>
            <select name="sourceId">
                <option value="">请选择客户来源</option>
            </select>
        </div>
    </div>
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-username"></i>
            </div>
            <select name="tradeId">
                <option value="">请选择客户行业</option>
            </select>
        </div>
    </div>
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-username"></i>
            </div>
            <select name="levelId">
                <option value="">请选择客户级别</option>
            </select>
        </div>
    </div>


    <div class="layui-btn-container layui-col-xs12">
        <button class="layui-btn" lay-submit lay-filter="demo-table-search">Search</button>
        <button type="reset" class="layui-btn layui-btn-primary">Clear</button>
        <button class="layui-btn" lay-submit lay-filter="demo-table-search1">查询导出</button>



    </div>
</form>


<table class="layui-hide" id="ID-table-demo-search"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">全部导出</button>
    </div>
</script>

<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="../../static/layui/layui.js"></script>
<script>
    layui.use(function () {
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;

        $.ajaxSettings.async = false;


        //客户来源下拉框
        let source = "source_id";
        $.ajax({
            url: "/customer/getDianList",
            data: {str: source},
            dataType: "json",
            success(res) {
                $("[name=sourceId]").empty()
                $("[name=sourceId]").append(`
                 <option value="">请选择客户来源</option>
                `)
                for (let x of res) {
                    $("[name=sourceId]").append(`
                        <option value="\${x.dianName}">\${x.dianValue}</option>
                `)
                }
            }
        })
        form.render();
        //客户行业下拉框
        let trade = "trade_id";
        $.ajax({
            url: "/customer/getDianList",
            data: {str: trade},
            dataType: "json",
            success(res) {
                $("[name=tradeId]").empty()
                $("[name=tradeId]").append(`
                 <option value="">请选择客户行业</option>
                `)
                for (let x of res) {
                    $("[name=tradeId]").append(`
                        <option value="\${x.dianName}">\${x.dianValue}</option>
                `)
                }
            }
        })
        form.render();
        //客户级别下拉框
        let level = "level_id";

        $.ajax({
            url: "/customer/getDianList",
            data: {str: level},
            dataType: "json",
            success(res) {
                $("[name=levelId]").empty()
                $("[name=levelId]").append(`
                 <option value="">请选择客户级别</option>
                `)
                for (let x of res) {
                    $("[name=levelId]").append(`
                        <option value="\${x.dianName}">\${x.dianValue}</option>
                `)
                }
            }
        })
        form.render();


        // 创建表格实例
        table.render({
            toolbar: '#toolbarDemo',
            limit: 5,
            elem: '#ID-table-demo-search',
            url: '/customer/getCustomerList', // 此处为静态模拟数据，实际使用时需换成真实接口
            cols: [[
                {type: 'radio', title: '😊', fixed: true}, // 单选框
                {field: 'customerId', title: '客户id', width: 80, sort: true, fixed: true},
                {field: 'customerName', title: '客户名称', width: 80},
                {field: 'customerSex', title: '客户性别', width: 80},
                {field: 'customerTime', title: '出生日期', width: 80},
                {field: 'customerPhone', title: '联系方式', width: 80},
                {field: 'customerAddr', title: '地址', width: 80},
                {field: 'sourceName', title: '来源', width: 80},
                {field: 'tradeName', title: '行业', width: 80},
                {field: 'levelName', title: '级别', width: 80},
                {field: 'customerEndTime', title: '最后跟进时间', width: 80},
            ]],
            parseData: function (res) { // res 即为原始返回的数据
                return {
                    "code": 0, // 解析接口状态
                    "msg": res.message, // 解析提示文本
                    "count": res.total, // 解析数据长度
                    "data": res.list // 解析数据列表
                };
            },
            request: {
                pageName: 'pageNum', // 页码的参数名称，默认：page
                limitName: 'pageSize' // 每页数据条数的参数名，默认：limit
            },
            page: true,
            height: 310
        });
        // 搜索提交
        form.on('submit(demo-table-search)', function (data) {
            var field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('ID-table-demo-search', {
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            layer.msg('搜索成功<br>此处为静态模拟数据，实际使用时换成真实接口即可');
            return false; // 阻止默认 form 跳转
        });





        // 搜索提交
        form.on('submit(demo-table-search1)', function (data) {
            var field = data.field; // 获得表单字段
            let customerName = field.customerName;
            let startTime = field.startTime;
            let endTime = field.endTime;
            let sourceId = field.sourceId;
            let tradeId = field.tradeId;
            let levelId = field.levelId;

            location.href="/customer/buFenDaoChu?customerName="+customerName+"&startTime="+startTime+
                '&endTime='+endTime+'&sourceId='+sourceId+'&tradeId='+tradeId+'&levelId='+levelId;
            return false; // 阻止默认 form 跳转
        });

        // 工具栏事件
        table.on('toolbar(ID-table-demo-search)', function(obj){
            var id = obj.config.id;
            var checkStatus = table.checkStatus(id);
            var othis = lay(this);
            switch(obj.event){
                case 'getCheckData':
                    location.href="/customer/daoChu"
                    break;
            };
        });

    });
</script>


</body>



</html>

</script>